/*
 * Copyright (c) 2012-2012 XXXX XXXXXX, Inc.
 * XXXX Road, XXXX, XXXX State, XXXX Post code, XXXX Country.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of XXXX
 * XXXXXX, Inc. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with XXXX.
 * 
 * History
 * Date        Ver Author        Change Description
 * ----------- --- ------------- ----------------------------------------
 * 08 Jun 2013 002 Karl          Update xpath
 */
package test.com.sms.selenium.singlepoint.util;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.sms.common.util.FileUtil;

import test.com.sms.selenium.framework.SeleniumPageUtil;
import test.com.sms.selenium.framework.SpSeleniumTestAbstract;
import test.com.sms.selenium.util.SeleniumUtil;

public class SpHotmailLoginPageUtil extends SeleniumPageUtil {
private static final Properties environmentProperties = new Properties();
	
	static
	{
		InputStream is = null;
		try
		{
			is = new FileInputStream (FileUtil.getFile("configuration/testenvironment_hotmail.properties", SpSeleniumTestAbstract.class));
			environmentProperties.load(is);
		}
		catch (Exception e)
		{
			
		}
		finally
		{
			try{is.close();}catch(Exception ex){}
		}
	}
	
	private static final String SP_ROOT_URL = 
			environmentProperties.getProperty("sp.protocol", "http").trim() + "://" + 
			environmentProperties.getProperty("sp.host", "www.hotmail.com/").trim();
	
	private static final String USER_ID = environmentProperties.getProperty("sp.userid", "smsbeyondsoft@hotmail.com"); 
	private static final String USER_PASSWORD = environmentProperties.getProperty("sp.password", "green123");
	
	// WebElement By
	public static final By LOGIN_INPUT_USERNAME = By.id("i0116");
	public static final By LOGIN_INPUT_PASSWORD = By.id("i0118");
	public static final By LOGIN_BUTTON_LOGIN = By.id("idSIButton9");
	public static final By LOGIN_CHECKBOX_AUTO_LOGIN = By.id("idChkBx_PWD_KMSI0Pwd");
	
	// get elements by methods
	public final static WebElement getLoginInputUsername(){
		return SeleniumUtil.getCachedElement(LOGIN_INPUT_USERNAME);
	}
	
	public final static WebElement getLoginInputPassword(){
		return SeleniumUtil.getCachedElement(LOGIN_INPUT_PASSWORD);
	}
	
	public final static WebElement getLoginButtonLogin(){
		return SeleniumUtil.getCachedElement(LOGIN_BUTTON_LOGIN);
	}
	
	public final static WebElement getLoginCheckboxAutoLogin(){
		return SeleniumUtil.getCachedElement(LOGIN_CHECKBOX_AUTO_LOGIN);
	}
	
	/** enter login page*/
	public final static void enterLoginPage() {
		SeleniumUtil.get(SP_ROOT_URL);
	}
	
	/** trigger login*/
	public final static void loginHotmail() {
		enterLoginPage();
		// login 
		SeleniumUtil.sendKeys(getLoginInputUsername(), USER_ID);
		SeleniumUtil.sendKeys(getLoginInputPassword(), USER_PASSWORD);
		SeleniumUtil.click(SeleniumUtil.getCachedElement(LOGIN_CHECKBOX_AUTO_LOGIN));
		SeleniumUtil.click(getLoginButtonLogin());
		// hotmail default page is inbox page
		SpHotmailInboxPageUtil.waitForPageToLoad();
	}
}
